#include<iostream>
#include<fstream>
#include<vector>
#include<fstream>
#include"Newton.h"

using namespace std;

class function1 :public Function
{
public:
	double operator()(double x)
	{
		return 1 / (1 + x * x);
	}
};


int main()
{
	function1 f;
	cout << "-----------------B----------------" << endl;
	for (int n = 2; n <= 8; n = n + 2)
	{
		vector<double> x;
		for (double i = 0;i <= n;i++)
		{
			double x1 = 10 * i / n - 5;
			x.push_back(x1);
		}
		vector<double> y;
		for (int i = 0;i <= n;i++)
		{
			double y1 = f(x[i]);
			y.push_back(y1);
		}
		Newton N(x, y);
		cout << "当n=" << n << "时:" << endl;
		N.output();
		cout << endl << endl;

		ofstream mcfile("B.txt", ios::app | ios::out);
		for (int i = 0;i <= n;i++)
		{
			mcfile << x[i] << "," << N.getTable(i, i) << endl;
		}
		mcfile.close();
    }
	return 0;
}